<template>
	<view class="sharehome">
		<view class="por mx15 sharemain text--center">
			<view class="por sharebox bg-white">
				<view class="codebox border-radius-7">
					<tki-qrcode ref="qrcode" :val="val" :size="size" :unit="unit" :loadMake="loadMake" />
				</view>
				<view class="f14 visitbox fcc flex-justify-center" @click="copy('code')">
					邀请码：28DWCA
					<image src="../../static/user/copy.png" class="copyicon ml5"></image>
				</view>
				<view class="visitlink f14">邀请链接：http:www.baidu.com</view>
				<view class="copylink f12" @click="copy('link')">
					复制链接
				</view> 
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState, mapActions } from 'vuex';
	import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue'
	export default {
		data() {
			return {
				// 要生成的二维码值
				val: '28DWCA',
				size: 306, // 二维码大小
				unit: 'upx', // 单位
				loadMake: true, // 组件加载完成后自动生成二维码
			}
		},
		components: {
			tkiQrcode
		},
		onLoad() {
			this.val ='http://web.jbcoin.cc/?code='+this.userInfo.inviteCode
		},
		methods: {
			async copy(type) {
				if(type=='code'){
					await uni.setClipboardData({ data: this.userInfo.inviteCode })
				}else{
					await uni.setClipboardData({ data: this.val })
				}
				uni.showToast({
					icon:'none',
					title: '复制成功'
				})
			},
			shareWeiXin(scene) {
				let _this = this
				let sc = scene
				_this.capture(sc)
			},
			capture(scene) {
				let _this = this
				let pages = getCurrentPages();
				let page = pages[pages.length - 1];
				let bitmap = null;
				let currentWebview = page.$getAppWebview();
				bitmap = new plus.nativeObj.Bitmap('amway_img');
				currentWebview.draw(bitmap, function() {
					bitmap.save("_doc/invite.jpg", {}, function(i) {
						uni.saveImageToPhotosAlbum({
							filePath: i.target,
							success: function() {
								_this.path = i.target
								bitmap.clear(); //销毁Bitmap图片  
								uni.showToast({
									title: '保存图片成功',
									mask: false,
									duration: 1500
								});
								uni.share({
									provider: "weixin",
									scene: scene,
									type: 2,
									imageUrl: _this.path,
									success: function(res) {
										console.log("success:" + JSON.stringify(res));
									},
									fail: function(err) {
										console.log("fail:" + JSON.stringify(err));
									}
								});
							}
						});
					}, function(e) {
						console.log('保存图片失败：' + JSON.stringify(e));
					});
				}, function(e) {
					console.log('截屏绘制图片失败：' + JSON.stringify(e));
				});
				//currentWebview.append(amway_bit);    
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.sharehome {
		min-height: 100vh;
		letter-spacing: 0;
		background: url(../../static/user/share-bg.png) no-repeat center;
		background-size: 100% 100%;
		.sharemain {
			padding-top: 202rpx;
			.visitlink{
				margin-top: 100rpx;
			}
			.copylink{
				width: 130rpx;
				height: 48rpx;
				line-height: 48rpx;
				margin: 30rpx auto 0;
				background-color: #e7f5ff;
				border: 2rpx solid #64abe1;
				border-radius: 4rpx;
				text-align: center;
				color: #308AE4;
			}
			.sharebox{
				padding-top: 122rpx;
				padding-bottom: 90rpx;
				border-radius: 32rpx;
			}
			.copyicon {
				width: 24rpx;
				height: 24rpx;
			}
			.codebox {
				width: 306rpx;
				height: 306rpx;
				border: 2rpx solid #d7d7d7;
				padding: 16rpx;
				background-color: #fff;
				margin:0 auto 34rpx;
				border-radius: 16rpx;
			}
		}
	}
</style>
